import asunit.framework.TestCase;

import mockAS2.SpyObject;
import mockAS2.mocks.ClassToBeMocked;

/**
 * Copyright (c) 2012 Gary Higham
 * Released under the MIT license
 * https://code.google.com/p/mock-as2/wiki/License
 *
 * Version: v0.1
 */
class mockAS2.SpyObjectTest extends TestCase {
	private var className : String = "tvpTestFramework.SpyObjectTest";
	private var dummy : ClassToBeMocked;
	private var spy : SpyObject;
	
	public function SpyObjectTest(testMethod : String) {
		super(testMethod);
	}
	
	public function setUp() : Void {
		dummy = new ClassToBeMocked();
		spy = new SpyObject(this, "dummy");
		trace("setUp dummy stuff: " + dummy);
	}
	
	public function tearDown() : Void {
		spy.restore();	
	}
	
	public function testCanSpyWhenAnObjectHasBeenDeleted() : Void {
		delete dummy;	
		assertTrue("Spy should say dummy is deleted", spy.hasBeenDeleted());
	}
	
	public function testSpyWhenObjectHasNotBeenDeleted() : Void {
		assertFalse("Spy should not say deleted", spy.hasBeenDeleted());
	}
	
	public function testSettingToUndefinedDoesNotMarkAsDeleted() : Void {
		dummy = undefined;
		assertFalse("Spy should not say deleted", spy.hasBeenDeleted());
	}
	
	public function testSettingToNullDoesNotMarkAsDeleted() : Void {
		dummy = null;
		assertFalse("Spy should not say deleted", spy.hasBeenDeleted());
	}
	
	public function testSpyWhenObjectHasBeenNulled() : Void {
		dummy = null;
		assertTrue("Variable should have been nulled", spy.hasBeenNulled());
	}
	
	public function testSpyWhenObjectHasNotBeenNulled() : Void {
		assertFalse("Variable should not have been nulled", spy.hasBeenNulled());
	}
}
